/**
 * ...
 * >author		João Vítor de Souza
 */

package com.cupcakeengine.utils 
{
	import com.cupcakeengine.CKEngine;
	import com.cupcakeengine.core.IUpdatable;
	import flash.display.Stage;	
	import flash.system.System;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.utils.getTimer;	

	public class Profiler implements IUpdatable
	{
		// ___________________________________________________________________ CONSTANTS	
		
		// ___________________________________________________________________ CLASS PROPERTIES
		
		private var _text 					: TextField;
		private var _timer					: uint;
		private var _lastTimer				: uint;
		
		// ___________________________________________________________________ INSTANCE PROPERTIES
		
		// ___________________________________________________________________ GETTERS AND SETTERS
		
		// ___________________________________________________________________ CONSTRUCTOR
		
		public function Profiler(stage:Stage):void
		{
			_text = new TextField();			
			_text.autoSize = TextFieldAutoSize.LEFT;
			stage.addChild(_text);
			
			_timer = getTimer();
			
			CKEngine.addUpdate(this, "profiler");
		}
		
		// ___________________________________________________________________ PUBLIC METHODS
		
		public function update():void
		{
			_lastTimer = _timer;
			_timer = getTimer();
			
			var fps:int = 1 / ((_timer - _lastTimer) * 0.001);
			
			_text.text = String(System.totalMemory / 1024) + "B - FPS " + fps + " / " + String(CKEngine.root.stage.frameRate);
		}
		
		// ___________________________________________________________________ PRIVATE METHODS
		
		// ___________________________________________________________________ EVENTS
	}
}

